﻿package mortal.game.view.forging.view
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import Message.Public.*;
    import baseEngine.modifiers.*;
    import com.gengine.utils.*;
    import com.greensock.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import frEngine.*;
    import frEngine.event.*;
    import frEngine.pools.*;
    import frEngine.primitives.object2d.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.model.player.*;
    import mortal.game.scene3D.model.pools.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.common.util.*;
    import mortal.game.view.forging.*;
    import mortal.game.view.forging.data.*;
    import mortal.game.view.palyer.*;
    import mortal.game.view.systemSetting.*;
    import mortal.mvc.core.*;

    public class GemStrengthenPanel extends ForgingPanelBase
    {
        private var _gemBg:GBitmap;
        private var _currSelGem:GemItem;
        private var _propName:GTextFiled;
        private var _propValue:GTextFiled;
        private var _upArrow:GBitmap;
        private var _upValue:GTextFiled;
        private var _progressBar:BaseProgressBar;
        private var _progressPoint:GBitmap;
        private var _commonStrengBtn:GButton;
        private var _onKeyStrengBtn:GButton;
        private var _upCostLabel:GTextFiled;
        private var _upCost:GTextFiled;
        private var _goldIcon:GBitmap;
        private var _autoBuyBox:GCheckBox;
        private var _canBeStrengthened:Boolean;
        private var _txtGemLevel:BitmapNumberText;
        private var _maxLevelLabel:GTextFiled;
        private var _gemCurrLevel:int;
        private var _gemSpr:Sprite;
        private var _gemItemArr:Array;
        private var _gemLevelText:GTextFiled;
        private var _gemQualDesc:GTextFiled;
        private var _gemCombat:BitmapNumberText;
        private var _combatUpValue:GTextFiled;
        private var _consumeItem:BaseItem;
        private var _currMaxGemNum:int;
        private var _reviewText1:GTextFiled;
        private var _reviewText2:GTextFiled;
        private var _upArrow1:GBitmap;
        private var _defaultText:GTextFiled;
        private var _maxLevelText:GTextFiled;
        private var _timeLine:TimelineLite;
        private var _effectPlayer:EffectPlayer;
        private var _strengEffectPlayer:EffectPlayer;
        private var _gemPlayer:MeshPlayer;
        private var _effectPath:String;
        private var _effectClickPath:String;
        private var _effectSuccPath:String;
        private var _isCommonStreng:Boolean;
        private var _swfPlayer:SWFPlayer;
        private var _isPlaying:Boolean;

        public function GemStrengthenPanel(param1:Window)
        {
            this._gemItemArr = new Array();
            super(param1);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.createChildren();
            return;
        }// end function

        private function onResLoadCompl(param1 = null) : void
        {
            if (isDisposed)
            {
                return;
            }
            this.createChildren();
            return;
        }// end function

        override protected function createChildren() : void
        {
            super.createChildren();
            _currOperEquip = UICompomentPool.getUICompoment(PlayerEquipItem);
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.TextBg3, 142 - 8, 1, this));
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = TextFormatAlign.CENTER;
            var _loc_2:* = GlobalStyle.textFormatHuang2;
            _loc_2.size = 16;
            this._gemLevelText = UIFactory.gTextField("", 187, 3, 50, 30, this, _loc_2);
            this._gemQualDesc = UIFactory.gTextField("", 162, 7, 214, 20, this, _loc_1);
            this._defaultText = UIFactory.gTextField("", 128, 7, 234, 20, this, _loc_1);
            this._defaultText.htmlText = Language.getString(40101);
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.Forging_GemStrengGridBg, 0, 182 + 16, this));
            this._gemSpr = UIFactory.sprite(0, 197 + 16, this);
            this.addChild(this._gemSpr);
            this.pushUIToDisposeVec(UIFactory.bg(148, 270, 208, 70, this, ImagesConst.AttributeBg));
            this.pushUIToDisposeVec(UIFactory.bg(162, 280, 177, 24, this, ImagesConst.RegionTitleBg));
            this.pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.Forging_Text_GemCombat, 178, 284, this));
            this._gemCombat = UIFactory.bitmapNumberText(232, 285, "FightInfoNum.png", 12, 15, -1, this);
            this._reviewText1 = UIFactory.gTextField(Language.getString(41160), 235, 282, 100, 20, this);
            this._upArrow1 = UIFactory.gBitmap(ImagesConst.upgradeArrow, 282 + 7, 286, this);
            this._upArrow1.visible = false;
            this._combatUpValue = UIFactory.gTextField("", 297 + 7, 282, 36, 20, this, GlobalStyle.textFormatLv);
            this._maxLevelText = UIFactory.gTextField(Language.getString(41161), 297 - 11, 281, 50, 20, this, GlobalStyle.textFormatHuang2);
            this._maxLevelText.visible = false;
            this._propName = UIFactory.gTextField(Language.getString(41162), 99 + 78, 258 + 54, 57, 20, this, GlobalStyle.textFormatAnjin);
            this._propValue = UIFactory.gTextField("", 155 + 78, 258 + 54, 40, 20, this);
            this._reviewText2 = UIFactory.gTextField(Language.getString(41160), 155 + 81, 258 + 54, 100, 20, this);
            this._upArrow = UIFactory.gBitmap(ImagesConst.upgradeArrow, 202 + 80, 261 + 54, this);
            this._upArrow.visible = false;
            this._upValue = UIFactory.gTextField("", 214 + 85, 258 + 54, 40, 20, this, GlobalStyle.textFormatLv);
            this._progressBar = UICompomentPool.getUICompoment(BaseProgressBar);
            this._progressBar.setBg(ImagesConst.StrengthenBarBg2, true, 268, 13);
            this._progressBar.setProgress(ImagesConst.StrengthenBar2, true, 14, 1, 240, 12);
            this._progressBar.setLabel(BaseProgressBar.ProgressBarTextPercent, 270, -4, 35, 20, GlobalStyle.textFormatHuang);
            this._progressBar.setValue(0, 10000);
            this._progressBar.x = 114;
            this._progressBar.y = 331 + 19;
            this.addChild(this._progressBar);
            this._progressPoint = UIFactory.gBitmap(ImagesConst.StrengthenBarPoint2, 0, -8 - 4, this._progressBar);
            this._commonStrengBtn = UIFactory.gButton(Language.getString(41163), 157, 366 + 12, 83, 27, this, "BrownBtn");
            this._commonStrengBtn.mouseChildren = false;
            this._commonStrengBtn.toolTipData = Language.getString(41164);
            this._onKeyStrengBtn = UIFactory.gButton(Language.getString(41165), 254, 366 + 12, 83, 27, this, "BrownBtn");
            this._onKeyStrengBtn.mouseChildren = false;
            this._onKeyStrengBtn.toolTipData = Language.getString(41166);
            this._commonStrengBtn.name = "gemStrenthen_oneKey";
            this._commonStrengBtn.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._onKeyStrengBtn.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(41167), 60, 320, 70, 20, this, GlobalStyle.textFormatLv));
            this._consumeItem = UICompomentPool.getUICompoment(BaseItem);
            this._consumeItem.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
            this._consumeItem.x = 68;
            this._consumeItem.y = 340;
            this.addChild(this._consumeItem);
            this._upCostLabel = UIFactory.gTextField(Language.getString(41168), 27 + 70, 387 + 23, 87, 20, this);
            this._upCostLabel.textColor = GlobalStyle.colorHuangUint;
            this._upCost = UIFactory.gTextField("", 111 + 70, 387 + 23, 40, 20, this, GlobalStyle.textFormatHuang);
            this._goldIcon = UIFactory.gBitmap(ImagesConst.Jinbi_bind, 143 + 70, 410, this);
            this._autoBuyBox = UIFactory.checkBox(Language.getString(41169), 194 + 70, 383 + 23, 140, 28, this);
            this._autoBuyBox.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this._maxLevelLabel = UIFactory.gTextField(Language.getString(41170), 90 + 27, -5, 50, 20, this._progressBar, GlobalStyle.textFormatHong);
            this._txtGemLevel = UIFactory.bitmapNumberText(128 + 70 + 70, 38 - 8, "StrengthenNumber.png", ForgingConst.ArtWordCellWidth, ForgingConst.ArtWordCellHeight, ForgingConst.ArtWordGap, this);
            this.canBeStrengthened = false;
            this.updateProgressBar(0, 100);
            this._swfPlayer = UICompomentPool.getUICompoment(SWFPlayer);
            this._gemSpr.addEventListener(MouseEvent.CLICK, this.onGemClickHandler);
            this.initAutoBuyState();
            this.update3DModel();
            return;
        }// end function

        private function initAutoBuyState() : void
        {
            if (ClientSetting.local.getIsDone(IsDoneType.AutoBuyGemProp))
            {
                this._autoBuyBox.selected = true;
            }
            else
            {
                this._autoBuyBox.selected = false;
            }
            return;
        }// end function

        override public function updateUI() : void
        {
            return;
        }// end function

        override public function addForgingEquip(param1:PlayerEquipItem) : void
        {
            var _loc_2:GemItem = null;
            if (param1 && param1.itemData)
            {
                super.addForgingEquip(param1);
                this.clearGemGrids();
                if (EquipmentUtil.isCanGemUpgrade(param1.itemData))
                {
                    this.createGemGrids2(this.getMaxGemNum());
                    this.updateGemList();
                    this.setGemHoleStatus(param1.itemData.extInfo.hole_num);
                }
                this.clearGemInfo();
                _loc_2 = this.getFirstGem();
                if (_loc_2)
                {
                    this.switchGem(_loc_2);
                    this._reviewText1.visible = false;
                }
                else
                {
                    this.update3DModel();
                    this.updateCombat();
                    this._propName.x = 177;
                }
                this._defaultText.text = "";
            }
            return;
        }// end function

        override public function updateForgingInfo() : void
        {
            var _loc_1:int = 0;
            var _loc_2:ItemData = null;
            var _loc_3:int = 0;
            if (this._currSelGem && this._currSelGem.itemData)
            {
                _loc_1 = _currOperEquip.itemData.extInfo["h" + this._currSelGem.posInEquip].split("#")[0];
                _loc_2 = new ItemData(_loc_1);
                this._currSelGem.itemData = _loc_2;
                _loc_3 = _loc_2.itemInfo.itemLevel;
                this.updateGemInfo(_loc_2);
                this._isCommonStreng = true;
                if (_loc_3 != this._gemCurrLevel)
                {
                    this._isCommonStreng = false;
                    MsgManager.showMouseMsg(Language.getString(41171), MsgRollTipsType.msgRollTips2);
                    this._gemCurrLevel = _loc_3;
                    this.addLevelUpEffect();
                    this.update3DModel();
                    this.updateCombat();
                    this.updateGemDesc();
                }
            }
            this.add3DStrengEffect();
            this.playSwfStrengEffect();
            this.addStrengFilterEffect();
            return;
        }// end function

        public function selectGem(param1:int) : void
        {
            var _loc_2:GemItem = null;
            for each (_loc_2 in this._gemItemArr)
            {
                
                if (_loc_2 && _loc_2.posInEquip == param1)
                {
                    this.switchGem(_loc_2);
                }
            }
            return;
        }// end function

        protected function createGemGrids(param1:int) : void
        {
            var _loc_3:GemItem = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            DisplayUtil.removeAllChild(this._gemSpr);
            this._gemItemArr.length = 0;
            var _loc_2:int = 0;
            while (_loc_2 < param1)
            {
                
                _loc_3 = UICompomentPool.getUICompoment(GemItem);
                this._gemItemArr.push(_loc_3);
                _loc_4 = 95 + 260 * int(_loc_2 % 2);
                _loc_5 = 19 + 54 * int(_loc_2 / 2);
                _loc_3.x = _loc_4;
                _loc_3.y = _loc_5;
                _loc_3.setItemStyle(ItemStyleConst.Small, ImagesConst.EquipItemBg, 5, 5);
                this._gemSpr.addChild(_loc_3);
                _loc_2++;
            }
            return;
        }// end function

        private function createGemGrids2(param1:int) : void
        {
            var _loc_5:GemItem = null;
            var _loc_2:* = 65 * param1 - 17;
            var _loc_3:int = 494;
            this._gemSpr.x = (_loc_3 - _loc_2) / 2;
            DisplayUtil.removeAllChild(this._gemSpr);
            this._gemItemArr.length = 0;
            var _loc_4:int = 0;
            while (_loc_4 < param1)
            {
                
                _loc_5 = UICompomentPool.getUICompoment(GemItem);
                this._gemItemArr.push(_loc_5);
                _loc_5.x = 65 * _loc_4;
                _loc_5.y = 0;
                _loc_5.name = "FrogingModule_Gem" + _loc_4;
                _loc_5.setItemStyle(ItemStyleConst.Small, ImagesConst.EquipItemBg, 5, 5);
                this._gemSpr.addChild(_loc_5);
                _loc_4++;
            }
            return;
        }// end function

        private function getMaxGemNum() : int
        {
            this._currMaxGemNum = EquipmentUtil.getGemHoleNum(_currOperEquip.itemData);
            return this._currMaxGemNum;
        }// end function

        private function setGemHoleStatus(param1:int) : void
        {
            var _loc_5:int = 0;
            var _loc_6:String = null;
            var _loc_2:int = 0;
            while (_loc_2 < this._gemItemArr.length)
            {
                
                if (_loc_2 < param1)
                {
                    if (this._gemItemArr[_loc_2].itemData == null)
                    {
                        this._gemItemArr[_loc_2].isOpened = true;
                    }
                }
                else
                {
                    this._gemItemArr[_loc_2].isOpened = false;
                }
                _loc_2++;
            }
            var _loc_3:int = 3;
            var _loc_4:* = this._gemItemArr.length - 1;
            while (_loc_4 >= param1)
            {
                
                _loc_5 = _loc_3 > 0 ? (_loc_3 * 3) : (3);
                _loc_6 = Language.getStringByParam(41172, _loc_5);
                (this._gemItemArr[_loc_4] as GemItem).toolTipData = HTMLUtil.addColor(_loc_6, "#FFFFFF");
                _loc_3 = _loc_3 - 1;
                _loc_4 = _loc_4 - 1;
            }
            return;
        }// end function

        private function onGemClickHandler(event:MouseEvent) : void
        {
            var _loc_2:GemItem = null;
            if (event.target is GemItem)
            {
                _loc_2 = event.target as GemItem;
            }
            if (_loc_2 == null || !_loc_2.itemData || _loc_2 == this._currSelGem)
            {
                return;
            }
            if (_loc_2.itemData)
            {
                this.switchGem(_loc_2);
            }
            return;
        }// end function

        private function switchGem(param1:GemItem) : void
        {
            if (this._currSelGem)
            {
                this._currSelGem.isSelected = false;
            }
            this._currSelGem = param1;
            param1.isSelected = true;
            this.canBeStrengthened = true;
            this._gemCurrLevel = this._currSelGem.itemData.itemInfo.itemLevel;
            this.updateGemInfo(param1.itemData);
            this.updatePropName();
            this.updateGemDesc();
            this.update3DModel();
            this.updateConsume();
            this.updateCombat();
            if (this._reviewText2.visible)
            {
                this._reviewText2.visible = false;
            }
            return;
        }// end function

        private function getOnlyOneGem() : GemItem
        {
            var _loc_1:GemItem = null;
            var _loc_2:int = 0;
            var _loc_3:GemItem = null;
            for each (_loc_3 in this._gemItemArr)
            {
                
                if (_loc_3.itemData)
                {
                    _loc_1 = _loc_3;
                    _loc_2++;
                }
            }
            if (_loc_2 == 1)
            {
                return _loc_1;
            }
            return null;
        }// end function

        private function getFirstGem() : GemItem
        {
            var _loc_1:GemItem = null;
            for each (_loc_1 in this._gemItemArr)
            {
                
                if (_loc_1.itemData)
                {
                    return _loc_1;
                }
            }
            return null;
        }// end function

        public function updateGemStrengInfo(param1:Object) : void
        {
            return;
        }// end function

        public function updateGemInfo(param1:ItemData) : void
        {
            var _loc_8:int = 0;
            var _loc_2:* = ItemConfig.instance.getConfig(param1.itemCode);
            var _loc_3:* = ItemConfig.instance.getConfig((param1.itemCode + 1));
            var _loc_4:* = _loc_2.itemLevel;
            var _loc_5:* = _loc_2.effect;
            if (_loc_3)
            {
                _loc_8 = _loc_3.effect;
            }
            var _loc_6:* = _currOperEquip.itemData.extInfo["h" + this._currSelGem.posInEquip].split("#")[1];
            var _loc_7:* = _loc_2.effectEx;
            if (_loc_4 == ForgingConst.GemMaxLevel)
            {
                _loc_8 = _loc_5;
            }
            this.updateProps(_loc_5, _loc_8);
            this.updateProgressBar(_loc_6, _loc_7);
            this.updateGemLevel(_loc_4);
            this.updateFee(ForgingConst.GemUpgradeFee);
            return;
        }// end function

        public function updateGemList() : void
        {
            var _loc_2:String = null;
            var _loc_3:ItemData = null;
            var _loc_5:int = 0;
            var _loc_1:* = new Array();
            var _loc_4:int = 1;
            while (_loc_4 <= this._currMaxGemNum)
            {
                
                _loc_2 = _currOperEquip.itemData.extInfo["h" + _loc_4];
                if (_loc_2 && _loc_2 != "0")
                {
                    _loc_5 = _loc_2.split("#")[0];
                    _loc_3 = new ItemData(_loc_5);
                }
                else
                {
                    _loc_3 = null;
                }
                _loc_1.push(_loc_3);
                _loc_4++;
            }
            _loc_4 = 0;
            while (_loc_4 < _loc_1.length)
            {
                
                if (_loc_1[_loc_4] != null)
                {
                    (this._gemItemArr[_loc_4] as GemItem).itemData = _loc_1[_loc_4];
                    (this._gemItemArr[_loc_4] as GemItem).isSelected = false;
                    (this._gemItemArr[_loc_4] as GemItem).isShowStrengLevel = true;
                    (this._gemItemArr[_loc_4] as GemItem).posInEquip = _loc_4 + 1;
                }
                else
                {
                    (this._gemItemArr[_loc_4] as GemItem).clear();
                }
                _loc_4++;
            }
            return;
        }// end function

        private function updateCombat(param1:int = 0) : void
        {
            var _loc_2:int = 0;
            var _loc_3:ItemData = null;
            var _loc_4:int = 0;
            if (param1 != 0)
            {
                _currOperEquip.itemData.extInfo.combat = param1;
            }
            if (this._currSelGem && this._currSelGem.itemData)
            {
                _loc_2 = EquipmentUtil.getGemCombat(this._currSelGem.itemData);
                this._gemCombat.text = _loc_2 + "";
                if (this._gemCurrLevel == ForgingConst.GemMaxLevel)
                {
                    this._upArrow1.visible = false;
                    this._maxLevelText.visible = true;
                    this._combatUpValue.text = "";
                }
                else
                {
                    this._upArrow1.visible = true;
                    this._maxLevelText.visible = false;
                    _loc_3 = new ItemData((this._currSelGem.itemData.itemCode + 1));
                    _loc_4 = EquipmentUtil.getGemCombat(_loc_3);
                    this._combatUpValue.text = "" + (_loc_4 - _loc_2);
                }
            }
            return;
        }// end function

        private function updatePropName() : void
        {
            var _loc_1:* = this._currSelGem.itemData.itemInfo.type;
            var _loc_2:* = ForgingUtil.instance.getGemPropName(_loc_1);
            this._propName.text = _loc_2;
            var _loc_3:* = GameDefConfig.instance.getItem("FightRoleAttribute", _loc_1).text;
            _loc_3 = _loc_3 == "maxLife" ? ("life") : (_loc_3);
            this._propName.toolTipData = AttributeUtil.getTipsByAttrName(_loc_3);
            return;
        }// end function

        private function updateGemDesc() : void
        {
            var _loc_1:* = ItemsUtil.getItemName(this._currSelGem.itemData);
            var _loc_2:* = this._currSelGem.itemData.itemInfo.itemLevel;
            this._gemLevelText.text = Language.getStringByParam(41173, _loc_2);
            this._gemQualDesc.htmlText = _loc_1;
            return;
        }// end function

        public function updateProgressBar(param1:Number, param2:Number) : void
        {
            if (param1 == 0)
            {
                this._progressPoint.visible = false;
            }
            else
            {
                this._progressPoint.visible = true;
            }
            if (param2 == 0)
            {
                param2 = ForgingConst.TotalStrengProgress;
                this._maxLevelLabel.visible = true;
            }
            else
            {
                this._maxLevelLabel.visible = false;
            }
            this._progressBar.setValue(param1, param2);
            this._progressPoint.x = this._progressBar.lastWidth + 3;
            return;
        }// end function

        public function updateProps(param1:int, param2:int) : void
        {
            this._propValue.text = "" + param1;
            this._upValue.text = "" + (param2 - param1);
            if (param1 == param2)
            {
                this._upArrow.visible = false;
                this._upValue.visible = false;
                this._propName.x = 99 + 30 + 80;
                this._propValue.x = 155 + 30 + 80;
            }
            else
            {
                this._upArrow.visible = true;
                this._upValue.visible = true;
                this._propName.x = 99 + 78;
                this._propValue.x = 155 + 78;
            }
            return;
        }// end function

        public function updateGemLevel(param1:int) : void
        {
            if (this._txtGemLevel.visible == false)
            {
                this._txtGemLevel.visible = true;
            }
            this._txtGemLevel.text = "+" + param1;
            if (param1 == ForgingConst.GemMaxLevel)
            {
                this.canBeStrengthened = false;
                this._txtGemLevel.x = 128 + 75 + 70 + 16;
                this._gemLevelText.x = 178;
                if (this._upArrow.visible)
                {
                    this._upArrow.visible = false;
                }
            }
            else
            {
                this._txtGemLevel.x = 150 + 70 + 70;
                this._gemLevelText.x = 187;
            }
            this._currSelGem.isShowStrengLevel = true;
            return;
        }// end function

        private function addLevelUpEffect() : void
        {
            var timeLite:TimelineLite;
            var originX:int;
            var newX:int;
            timeLite = new TimelineLite();
            var originY:int;
            var newY:int;
            if (this._gemCurrLevel < ForgingConst.GemMaxLevel)
            {
                originX = 220 + 70 + 16;
                newX = 140 + 70 + 16;
            }
            else
            {
                originX = 203 + 70;
                newX = 123 + 70;
            }
            timeLite.append(new TweenLite(this._txtGemLevel, 0.17, {scaleX:5, scaleY:5, x:newX, y:newY}));
            timeLite.append(new TweenLite(this._txtGemLevel, 0.17, {scaleX:1, scaleY:1, x:originX, y:originY, onComplete:function () : void
            {
                timeLite.stop();
                timeLite = null;
                return;
            }// end function
            }));
            timeLite.play();
            return;
        }// end function

        private function updateConsume() : void
        {
            var _loc_1:* = new ItemData(ForgingConst.GemStrengItemCode);
            this._consumeItem.itemData = _loc_1;
            this.updateConsumeState();
            return;
        }// end function

        override public function updateConsumeState() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            if (this._consumeItem.itemData)
            {
                _loc_1 = this._consumeItem.itemData.itemInfo.type;
                _loc_2 = 1;
                _loc_3 = Cache.instance.pack.backPackCache.getItemCountByItemData(this._consumeItem.itemData);
                if (_loc_2 <= _loc_3)
                {
                    this._consumeItem.isGray = false;
                }
                else
                {
                    this._consumeItem.isGray = true;
                }
            }
            return;
        }// end function

        override public function updateMoneyState() : void
        {
            if (_currOperEquip.itemData)
            {
                this.updateFee(ForgingConst.GemUpgradeFee);
            }
            return;
        }// end function

        public function updateFee(param1:int) : void
        {
            if (param1 == 0)
            {
                this._upCost.text = "";
            }
            else
            {
                this._upCost.text = "" + param1;
                if (param1 > Cache.instance.role.money.coin + Cache.instance.role.money.coinBind)
                {
                    this._upCost.textColor = GlobalStyle.colorHongUint;
                }
                else
                {
                    this._upCost.textColor = GlobalStyle.colorHuangUint;
                }
            }
            return;
        }// end function

        private function clearGemGrids() : void
        {
            DisplayUtil.removeAllChild(this._gemSpr);
            this._gemItemArr.length = 0;
            return;
        }// end function

        private function clearGemInfo() : void
        {
            this._txtGemLevel.visible = false;
            this._propValue.text = "";
            this._upValue.text = "";
            this.canBeStrengthened = false;
            this._gemQualDesc.text = "";
            this._gemLevelText.text = "";
            this._gemCombat.text = "";
            this._combatUpValue.text = "";
            this._defaultText.text = "";
            this._consumeItem.itemData = null;
            this._reviewText1.visible = true;
            this._reviewText2.visible = true;
            this._upArrow.visible = false;
            this._upArrow1.visible = false;
            this._maxLevelText.visible = false;
            this._propName.x = 177;
            if (this._currSelGem)
            {
                this._currSelGem.isSelected = false;
            }
            this.currSelGem = null;
            this._gemCurrLevel = 0;
            this.updateProgressBar(0, ForgingConst.TotalStrengProgress);
            this.updateFee(0);
            return;
        }// end function

        override public function clearUI() : void
        {
            var _loc_1:GemItem = null;
            this.clearGemInfo();
            this.updateProgressBar(0, ForgingConst.TotalStrengProgress);
            this.updateFee(0);
            for each (_loc_1 in this._gemItemArr)
            {
                
                _loc_1.itemData = null;
            }
            DisplayUtil.removeAllChild(this._gemSpr);
            this.update3DModel();
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_2:Object = {};
            if (this._currSelGem && this._currSelGem.itemData)
            {
                _loc_2.gemUid = this._currSelGem.itemData.uid;
                _loc_2.holeIndex = this._currSelGem.posInEquip;
                _loc_2.equipUid = _currOperEquip.itemData.uid;
                if (event.currentTarget == this._commonStrengBtn)
                {
                    if (this._isPlaying)
                    {
                        this.stopAllStrengthenEffect();
                    }
                    _loc_2.upgradeType = EOperType._EOperTypeSimple;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.UpgradeGem, _loc_2));
                }
                if (event.currentTarget == this._onKeyStrengBtn)
                {
                    if (this._isPlaying)
                    {
                        this.stopAllStrengthenEffect();
                    }
                    _loc_2.upgradeType = EOperType._EoperTypeBatch;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.UpgradeGem, _loc_2));
                }
            }
            if (event.target == this._autoBuyBox)
            {
                if (this._autoBuyBox.selected == true)
                {
                    ClientSetting.local.setIsDone(true, IsDoneType.AutoBuyGemProp);
                }
                else
                {
                    ClientSetting.local.setIsDone(false, IsDoneType.AutoBuyGemProp);
                }
            }
            return;
        }// end function

        public function addStrengFilterEffect() : void
        {
            var _loc_1:Array = [FilterConst.colorGlowFilter(11252925)];
            var _loc_2:Array = [FilterConst.colorGlowFilter(11252925), FilterConst.colorGlowFilter(GlobalStyle.colorHuangUint)];
            EffectManager.glowFilterUnReg(this._progressBar);
            EffectManager.glowFilterReg(this._progressBar, _loc_1, 1, 10, 0, 1);
            return;
        }// end function

        private function add3DModel() : void
        {
            var _loc_1:* = (_window as ForgingModule).rect3d;
            if (_loc_1 != null)
            {
                Rect3DManager.instance.windowShowHander(null, _window);
                if (!_leftImg2d)
                {
                    if (!_bgData)
                    {
                    }
                    _leftImg2d = new Img2D(null, _bgData, ForgingConst.Bg3DRect, false);
                }
                _loc_1.addImg(_leftImg2d);
            }
            return;
        }// end function

        private function remove3DModel() : void
        {
            var _loc_1:* = (_window as ForgingModule).rect3d;
            if (_loc_1)
            {
                if (this._effectPlayer)
                {
                    _loc_1.disposeObj3d(this._effectPlayer);
                    this._effectPlayer = null;
                }
                _loc_1.disposeObj3d(this._strengEffectPlayer);
                this._strengEffectPlayer = null;
                _loc_1.disposeObj3d(this._gemPlayer);
                this._gemPlayer = null;
            }
            return;
        }// end function

        private function clear3D() : void
        {
            this.remove3DModel();
            var _loc_1:* = (_window as ForgingModule).rect3d;
            _loc_1.removeImg(_leftImg2d);
            this._bgData = null;
            this._leftImg2d = null;
            return;
        }// end function

        private function add3DStrengEffect() : void
        {
            var _loc_2:String = null;
            var _loc_3:int = 0;
            var _loc_1:* = (_window as ForgingModule).rect3d;
            if (_loc_1)
            {
                _loc_1.disposeObj3d(this._strengEffectPlayer);
                _loc_2 = this._isCommonStreng == true ? (this._effectClickPath) : (this._effectSuccPath);
                this._strengEffectPlayer = EffectPlayerPool.instance.getEffectPlayer(_loc_2, null, _loc_1.renderList, false);
                if (this._isCommonStreng)
                {
                    _loc_3 = 93;
                    this._strengEffectPlayer.setScale(0.7, 0.7, 0.7);
                }
                else
                {
                    _loc_3 = 103;
                    this._strengEffectPlayer.setScale(0.9, 0.9, 0.9);
                }
                this._strengEffectPlayer.play(PlayMode.ANIMATION_STOP_MODE);
                FrEventDispatcher.instance.proxyAddEventListener(this._strengEffectPlayer, Engine3dEventName.PLAYEND, this.playEndHander);
                _loc_1.addObject3d(this._strengEffectPlayer, 180 + 141 - 71, _loc_3);
            }
            return;
        }// end function

        private function playEndHander(event:Event) : void
        {
            var _loc_2:* = event.currentTarget as EffectPlayer;
            var _loc_3:* = (_window as ForgingModule).rect3d;
            if (_loc_3)
            {
                _loc_3.disposeObj3d(_loc_2);
            }
            return;
        }// end function

        protected function updateMeshModel(param1:ItemData) : void
        {
            var _loc_3:int = 0;
            var _loc_4:TModel = null;
            var _loc_5:int = 0;
            var _loc_6:String = null;
            var _loc_7:String = null;
            var _loc_2:* = (_window as ForgingModule).rect3d;
            if (param1)
            {
                _loc_3 = param1.itemInfo.itemLevel;
                if (_loc_2)
                {
                    if (_loc_3 <= ForgingConst.GemEffectLevel1)
                    {
                        this._effectPath = ForgingConst.EffectPath1;
                        this._effectClickPath = ForgingConst.EffectClickPath1;
                        this._effectSuccPath = ForgingConst.EffectSuccPath1;
                    }
                    else if (_loc_3 <= ForgingConst.GemEffectLevel2)
                    {
                        this._effectPath = ForgingConst.EffectPath2;
                        this._effectClickPath = ForgingConst.EffectClickPath2;
                        this._effectSuccPath = ForgingConst.EffectSuccPath2;
                    }
                    else if (_loc_3 <= ForgingConst.GemEffectLevel3)
                    {
                        this._effectPath = ForgingConst.EffectPath3;
                        this._effectClickPath = ForgingConst.EffectClickPath3;
                        this._effectSuccPath = ForgingConst.EffectSuccPath3;
                    }
                    else if (_loc_3 <= ForgingConst.GemEffectLevel4)
                    {
                        this._effectPath = ForgingConst.EffectPath4;
                        this._effectClickPath = ForgingConst.EffectClickPath4;
                        this._effectSuccPath = ForgingConst.EffectSuccPath4;
                    }
                    this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(this._effectPath, null, _loc_2.renderList, false);
                    this._effectPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
                    _loc_4 = ModelConfig.instance.getInfoByType(param1.itemInfo.type);
                    _loc_5 = param1.itemInfo.color;
                    if (_loc_4)
                    {
                        _loc_6 = _loc_4["mesh" + (_loc_5 - 1)];
                        _loc_7 = _loc_4["texture" + (_loc_5 - 1)];
                    }
                    this._gemPlayer = FrObjectPool.getObject(MeshPlayer, this);
                    this._gemPlayer.load(_loc_6 + ".mesh", _loc_7, _loc_2.renderList);
                    this._gemPlayer.hangBoneName = BoneConst.MountHangModelBone;
                    this._effectPlayer.hang(this._gemPlayer, "parent1");
                    _loc_2.addObject3d(this._effectPlayer, 180 + 70, 210 - 8 - 34);
                }
            }
            else if (_loc_2)
            {
                this._effectPlayer = EffectPlayerPool.instance.getEffectPlayer(ForgingConst.EffectPath1, null, _loc_2.renderList, false);
                this._effectPlayer.play(PlayMode.ANIMATION_LOOP_MODE);
                _loc_2.addObject3d(this._effectPlayer, 180 + 70, 210 - 8 - 34);
            }
            return;
        }// end function

        override public function update3DModel() : void
        {
            var _loc_1:ItemData = null;
            this.remove3DModel();
            if (this._currSelGem && this._currSelGem.itemData)
            {
                _loc_1 = this._currSelGem.itemData;
                switch(this._currSelGem.itemData.itemInfo.color)
                {
                    case EJewelQuality._EJewelQuality1:
                    {
                        break;
                    }
                    case EJewelQuality._EJewelQuality2:
                    {
                        break;
                    }
                    case EJewelQuality._EJewelQuality3:
                    {
                        break;
                    }
                    case EJewelQuality._EJewelQuality4:
                    {
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            this.updateMeshModel(_loc_1);
            return;
        }// end function

        public function set canBeStrengthened(param1:Boolean) : void
        {
            this._canBeStrengthened = param1;
            if (param1)
            {
                this._commonStrengBtn.mouseEnabled = true;
                this._commonStrengBtn.filters = null;
                this._onKeyStrengBtn.mouseEnabled = true;
                this._onKeyStrengBtn.filters = null;
            }
            else
            {
                this._commonStrengBtn.mouseEnabled = false;
                this._commonStrengBtn.filters = [FilterConst.colorFilter2];
                this._onKeyStrengBtn.mouseEnabled = false;
                this._onKeyStrengBtn.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

        private function playSwfStrengEffect() : void
        {
            var _loc_1:String = null;
            if (!this._isPlaying)
            {
                _loc_1 = this._isCommonStreng == true ? ("StrengDownCommonEffect.swf") : ("StrengDownPerfectEffect.swf");
                if (this._isCommonStreng)
                {
                    this._swfPlayer.move(250 - 5 + 10, 107 + 252);
                }
                else
                {
                    this._swfPlayer.move(250 - 5 + 23, 107 + 244);
                }
                this._swfPlayer.load(_loc_1, ModelType.NormalSwf, null);
                this._swfPlayer.framesPlayerCompleteHandler = this.onStrengEffectEnd;
                this.addChild(this._swfPlayer);
                this._isPlaying = true;
            }
            return;
        }// end function

        private function onStrengEffectEnd(param1:SWFPlayer) : void
        {
            this._swfPlayer.framesPlayerCompleteHandler = null;
            this._swfPlayer.stop();
            DisplayUtil.removeMe(this._swfPlayer);
            this._isPlaying = false;
            return;
        }// end function

        public function stopAllStrengthenEffect() : void
        {
            if (this._isPlaying)
            {
                this._swfPlayer.stop();
                DisplayUtil.removeMe(this._swfPlayer);
                this._isPlaying = false;
            }
            return;
        }// end function

        public function set currSelGem(param1:GemItem) : void
        {
            this._currSelGem = param1;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            var _loc_2:GemItem = null;
            super.disposeImpl(param1);
            if (_isCreateChildren)
            {
                _isCreateChildren = false;
                this._commonStrengBtn.name = "";
                for each (_loc_2 in this._gemItemArr)
                {
                    
                    _loc_2.dispose(param1);
                    _loc_2.name = "";
                    _loc_2 = null;
                }
                this._propName.dispose(param1);
                this._propValue.dispose(param1);
                this._upArrow.dispose(param1);
                this._upValue.dispose(param1);
                this._progressBar.dispose(param1);
                this._progressPoint.dispose(param1);
                this._commonStrengBtn.dispose(param1);
                this._onKeyStrengBtn.dispose(param1);
                this._upCostLabel.dispose(param1);
                this._upCost.dispose(param1);
                this._goldIcon.dispose(param1);
                this._autoBuyBox.dispose(param1);
                this._maxLevelLabel.dispose(param1);
                this._txtGemLevel.dispose(param1);
                this._gemQualDesc.dispose(param1);
                this._gemCombat.dispose(param1);
                this._combatUpValue.dispose(param1);
                this._consumeItem.dispose(param1);
                this._gemLevelText.dispose(param1);
                this._reviewText1.dispose(param1);
                this._reviewText2.dispose(param1);
                this._upArrow1.dispose(param1);
                this._defaultText.dispose(param1);
                this._maxLevelText.dispose(param1);
                this._swfPlayer.dispose(param1);
                this._gemSpr.removeEventListener(MouseEvent.CLICK, this.onGemClickHandler);
                UICompomentPool.disposeObject(this._gemSpr, Sprite);
                this._propName = null;
                this._propValue = null;
                this._upArrow = null;
                this._upValue = null;
                this._progressBar = null;
                this._progressPoint = null;
                this._commonStrengBtn = null;
                this._onKeyStrengBtn = null;
                this._upCostLabel = null;
                this._upCost = null;
                this._goldIcon = null;
                this._autoBuyBox = null;
                this._maxLevelLabel = null;
                this._txtGemLevel = null;
                this._currSelGem = null;
                this._gemSpr = null;
                this._gemQualDesc = null;
                this._gemCombat = null;
                this._combatUpValue = null;
                this._consumeItem = null;
                this._gemLevelText = null;
                this._reviewText1 = null;
                this._reviewText2 = null;
                this._upArrow1 = null;
                this._defaultText = null;
                this._maxLevelText = null;
                this._swfPlayer = null;
                this._gemItemArr.length = 0;
                this._currMaxGemNum = 0;
                this.remove3DModel();
                this._isPlaying = false;
            }
            return;
        }// end function

    }
}
